import java.util.Scanner;

public class 包含不超过两种字符的最长子串 {
    /*
    https://www.nowcoder.com/practice/90d6a362fa7d4c519d557da797bb02ce?tpId=196&tqId=40552&ru=/exam/oj
    滑动窗口
     */
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        char[] s = in.next().toCharArray();
        int n = s.length;
        //用一个hash来存储
        int[] arr = new int[26];
        //记录当前的字符数量
        int curCount = 0;
        //记录最长的长度
        int maxCount = 0;
        int left = 0;
        for(int right = 0;right < n;right++){
            //进窗口
            if(arr[s[right] - 'a']++ == 0){
                curCount++;
            }
            //判断窗口是否大于2
            while(curCount > 2){
                if(--arr[s[left++] - 'a'] == 0){
                    curCount--;
                }
            }
            maxCount = Math.max(maxCount,right - left + 1);
        }
        System.out.println(maxCount);
    }
}
